package com.zhy.generator.config;

import com.zhy.generator.codegen.dom.xml.Attribute;
import com.zhy.generator.codegen.dom.xml.XmlElement;

import java.util.List;

import static com.zhy.generator.codegen.util.Messages.getString;
import static com.zhy.generator.codegen.util.StringUtility.stringHasValue;

/**
 *
 * @author Jeff Butler
 *
 */
public class PluginConfiguration extends TypedPropertyHolder {
    public PluginConfiguration() {
    }

    public XmlElement toXmlElement() {
        XmlElement answer = new XmlElement("plugin"); //$NON-NLS-1$
        if (getConfigurationType() != null) {
            answer.addAttribute(new Attribute("type", getConfigurationType())); //$NON-NLS-1$
        }

        addPropertyXmlElements(answer);

        return answer;
    }

    public void validate(List<String> errors, String contextId) {
        if (!stringHasValue(getConfigurationType())) {
            errors.add(getString("ValidationError.17", contextId));
        }
    }
}
